/*
 * @Author: Clark
 * @Email: haixuanwoTxh@gmail.com
 * @Date: 2023-05-27 14:10:09
 * @LastEditors: Clark
 * @LastEditTime: 2023-05-27 14:21:34
 * @Description: file content
 */
/* include my_shm */
#include	"unpipc.h"

void *
my_shm(size_t nbytes)
{
	void	*shared;

#if 1
	shared = mmap(NULL, nbytes, PROT_READ | PROT_WRITE,
				  MAP_ANON | MAP_SHARED, -1, 0);

#else
	int		fd;

		/* 4memory map /dev/zero */
	if ( (fd = open("/dev/zero", O_RDWR)) == -1)
		return(MAP_FAILED);
	shared = mmap(NULL, nbytes, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
	close(fd);
#endif
	return(shared);		/* MAP_FAILED on error */
}
/* end my_shm */

void *
My_shm(size_t nbytes)
{
	void	*shared;

	if ( (shared = my_shm(nbytes)) == MAP_FAILED)
		err_sys("my_shm error");
	return(shared);
}
